const mongoose = require('mongoose');

async function main() {
  await mongoose.connect('mongodb://localhost:27017/huan');

  const PersonSchema = new mongoose.Schema({
    name: String,
    age: Number,
    hobbies: [String],
  });

  const Person = mongoose.model('Person', PersonSchema);

  const huan = new Person();
  huan.name = 'huan';
  huan.age = 20;

  await huan.save();

  const huan2 = new Person();
  huan2.name = 'huan2';
  huan2.age = 21;
  huan2.hobbies = ['reading', 'football'];

  await huan2.save();

  const persons1 = await Person.find();
  console.log(persons1);

  const persons2 = await Person.find({
    $and: [{ age: { $gte: 20 } }, { name: /dong/ }],
  });
  console.log(persons2);

  const persons3 = await Person.find({
    age: { $in: [20, 21] },
  });
  console.log(persons3);
}

main().catch((err) => console.log(err));
